<template>
  <el-dialog :title="maintainShow? '添加保养项':'添加点检项'" :visible.sync="addspotCheckShow" width="60%"
    :before-close="setparentShow" append-to-body>
    <spotCheckItem v-if="!maintainShow" :spotCheckIds='spotCheckIds' :addspotCheckShow='addspotCheckShow'
      @add-spotCheck="addSpotCheck" />
    <maintainItem v-else :spotCheckIds='spotCheckIds' :addspotCheckShow='addspotCheckShow'
      @add-maintain="addSpotCheck" />
    <span slot="footer" class="dialog-footer">
      <el-button @click="setparentShow">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import commonMixin from '@/views/_common/mixin'
import spotCheckItem from '@/views/tpm/spotCheckManage/spotCheckItem'
import maintainItem from '@/views/tpm/maintainManage/maintainItem'
export default {
  name: 'addSpotCheck',
  mixins: [commonMixin],
  components: { spotCheckItem, maintainItem },
  props: {
    addspotCheckShow: {
      type: Boolean,
      default: false,
    },
    maintainShow: {
      type: Boolean,
      default: false,
    },
    spotCheckIds: {
      type: Array,
      default: function () {
        return []
      },
    },
  },
  data() {
    return {
      itemData: [],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 控制父级关闭弹框
    setparentShow() {
      this.itemData = []
      this.$parent.addspotCheckShow = false
      this.$parent.maintainShows = false
    },
    addSpotCheck(val) {
      this.itemData = val
    },
    submit() {
      this.$emit('addItem', this.itemData)
    },
  },
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__body {
  padding: 10px 20px 0;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
}
</style>